/**
 * 根据标签筛选出对应的文章内容
 */

const mdModel = require('../models/mdModel')

function getInfo(query) {
  return new Promise((resolve, reject) => {
    mdModel.findOne({ user_id: query.user_id }, (err, suc) => {
      err? reject(err) : resolve(suc)
    }) 
  }).then(suc => {
    if (suc !== null) {
      let res = []
      for (let i = 0; i < suc.user_md.length; i++) {
        let strArr = suc.user_md[i].label.split(',')
        if (strArr.indexOf(query.label) !== -1) {
          res.push(suc.user_md[i])
        }
      }

      return res
    } else {
      return []
    }
  })
}

module.exports = {
  getInfo
}